package model.handlers;

import database.Database;
import java.sql.SQLException;
import model.*;
/**
 *
 * @author Sonny Sandberg
 */
public abstract class ProgramValueHandler
{
    public static ProgramValue getCurrentProgramValueModelObject() throws SQLException, ClassNotFoundException
    {
        Database db = new Database();
        
        String[][] result = db.getFromDB("bs_program_values", "", "ORDER BY id DESC", "LIMIT 1", "id", "vat", "environment_tax");
        db.closeDB();
        
        if (result.length > 0)
        {
            return new ProgramValue(Integer.parseInt(result[0][0]), Double.parseDouble(result[0][1]), Double.parseDouble(result[0][2]));        
        }
        else
        {
            return null;
        }
    }

    public static ProgramValue getSpecificProgramValueModelObject(int id) throws SQLException, ClassNotFoundException
    {
        Database db = new Database();
        
        String[][] result = db.getFromDB("bs_program_values", "WHERE id = '"+id+"'", "", "", "id", "vat", "environment_tax");
        db.closeDB();
        
        if (result.length > 0)
        {
            return new ProgramValue(Integer.parseInt(result[0][0]), Double.parseDouble(result[0][1]), Double.parseDouble(result[0][2]));
        }
        else
        {
            return null;
        }
    }
}
